var index = 0;
var second = $(".game_onem");
function setImgSrc() {
//	alert(index)
	$(".game_one_bot img").eq(index).attr("src", "../img/game/bottle_or.png");
	index++;
}
var pages=$(".page");
var time2;
function donghua()
{
	time2 = setInterval(function(){
		pages.css("display","none")
		pages.eq(1).css("display","block");
	},2000)
}

var s = 6;
//function daoshu() {
	var time3 = setInterval(function() {
		s--;
		second.html(s + "s");
		if(s == 0) {
//			clearInterval(deviceMotionHandler());
			clearInterval(time3);
			donghua()
//			rest();
		}
	}, 1000)
//}
if(window.DeviceMotionEvent) {
	window.addEventListener('devicemotion', deviceMotionHandler, false);
}
var SHAKE_THRESHOLD = 2000;
var last_update = 0;
var x, y, z, last_x = 0,
	last_y = 0,
	last_z = 0;
var count = 0;

function deviceMotionHandler(eventData) {
	var acceleration = eventData.accelerationIncludingGravity; // 获取含重力的加速度
	var myDate = new Date();
	var curTime = myDate.getTime(); // 获取当前时间
	if((curTime - last_update) > 100) {
		var diffTime = curTime - last_update; //时间差
		last_update = curTime;
		x = acceleration.x;
		y = acceleration.y;
		z = acceleration.z;
		var speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000;
		if(speed > SHAKE_THRESHOLD) {
			//					alert(3)

			count++;
			if(count == 0) {
				setImgSrc()
			} else if(count == 5) {
				setImgSrc()
			} else if(count == 10) {
				setImgSrc()
			} else if(count == 15) {
				setImgSrc()
			} else if(count == 25) {
				setImgSrc()
			} else if(count == 30) {
				setImgSrc()
			} else if(count == 35) {
				setImgSrc()
			} else if(count == 40) {
				setImgSrc()
			} else if(count == 45) {
				setImgSrc()
			} else if(count >= 50) {
				setImgSrc()
			}
		}
	}
}